home *** CD-ROM | disk | FTP | other *** search
/ Inside the White House / Inside the White House.iso / export.dir / 00032.ls < prev    next >
Encoding:
Text File  |  1995-07-11  |  3.3 KB  |  115 lines

  1. on exportText textString
  2.   if the machineType = 256 then
  3.     openXLib("dialogs.dll")
  4.     set dialog to dialogs(mnew)
  5.   else
  6.     set dialog to dialogs(mnew)
  7.   end if
  8.   if the machineType = 256 then
  9.     set fname to dialog(mPutFile, "Export File", EMPTY, "*.txt")
  10.   else
  11.     set fname to dialog(mPutFile, "Export File", EMPTY)
  12.   end if
  13.   if fname <> EMPTY then
  14.     if the machineType = 256 then
  15.       openXLib("fileio.dll")
  16.       set File to FileIO(mnew, "write", fname)
  17.     else
  18.       set File to FileIO(mnew, "write", fname)
  19.     end if
  20.     if not objectp(File) then
  21.       alert("Unable to save file.  Please check available disk space.")
  22.     else
  23.       set MAXLEN to 80
  24.       if the machineType = 256 then
  25.         set CRLF to RETURN & numToChar(10)
  26.       else
  27.         set CRLF to EMPTY
  28.       end if
  29.       set textLen to the number of chars in textString
  30.       set textLines to the number of lines in textString
  31.       if the machineType = 256 then
  32.         set textString to breakIntoLines(textString)
  33.       end if
  34.       set numLines to the number of lines in textString
  35.       put numLines
  36.       if the machineType = 256 then
  37.         repeat with i = 1 to numLines
  38.           File(mWriteString, line i of textString & CRLF)
  39.         end repeat
  40.       else
  41.         File(mWriteString, textString)
  42.       end if
  43.       File(mdispose)
  44.       return 1
  45.     end if
  46.   else
  47.     return 0
  48.   end if
  49.   if the machineType = 256 then
  50.     dialogs(mdispose)
  51.   else
  52.     dialogs(mdispose)
  53.   end if
  54. end
  55.  
  56. on breakIntoLines textString
  57.   set MAXLEN to 80
  58.   set rString to EMPTY
  59.   set rLines to 0
  60.   set numLines to the number of lines in textString
  61.   repeat with myLine = 1 to numLines
  62.     if the number of chars in line myLine of textString > MAXLEN then
  63.       set testLine to line myLine of textString
  64.       repeat while the number of chars in testLine > MAXLEN
  65.         if alphanum(char MAXLEN of testLine) and alphanum(char MAXLEN + 1 of testLine) then
  66.           set end to findBreakpoint(testLine, MAXLEN)
  67.           if end <> 0 then
  68.             put char 1 to end of line myLine of testLine after rString
  69.             put RETURN after rString
  70.             set begin to end + 1
  71.             set end to the number of chars in testLine
  72.             set testLine to char begin to end of testLine
  73.           else
  74.             put char 1 to MAXLEN of line myLine of testLine after rString
  75.             put RETURN after rString
  76.             set begin to MAXLEN + 1
  77.             set end to the number of chars in testLine
  78.             set testLine to char begin to end of testLine
  79.           end if
  80.           next repeat
  81.         end if
  82.         put char 1 to MAXLEN of line myLine of testLine after rString
  83.         put RETURN after rString
  84.         set begin to MAXLEN + 1
  85.         set end to the number of chars in testLine
  86.         set testLine to char begin to end of testLine
  87.       end repeat
  88.       if the number of chars in testLine > 0 then
  89.         put testLine after rString
  90.       end if
  91.       next repeat
  92.     end if
  93.     put line myLine of textString after rString
  94.   end repeat
  95.   return rString
  96. end
  97.  
  98. on alphanum ch
  99.   if (charToNum(ch) > 32) and (charToNum(ch) < 127) then
  100.     return 1
  101.   else
  102.     return 0
  103.   end if
  104. end
  105.  
  106. on findBreakpoint textString, length
  107.   set SPACE to " "
  108.   repeat with i = length down to 1
  109.     if char i of textString = SPACE then
  110.       return i
  111.     end if
  112.   end repeat
  113.   return 0
  114. end
  115.